﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Diagnostics;

using DreamCube.Foundation.Basic.Win32API;
using DCObject= DreamCube.Foundation.Basic.Objects;

namespace Test
{
    public static class TestQueryPerformanceCounter
    {
        public static void Start()
        {
            long count = 0;
            long count1 = 0;
            long freq = 0;
            double result = 0;
            DreamCube.Foundation.Basic.Win32API.API.kernel32.QueryPerformanceFrequency(ref freq);
            DreamCube.Foundation.Basic.Win32API.API.kernel32.QueryPerformanceCounter(ref count);

            int heisetoufa;
            for (heisetoufa = 1; heisetoufa < 3; heisetoufa++)
            {
                Thread.Sleep(1000);
                //Console.WriteLine("第" + heisetoufa + "行");
                //if (heisetoufa == 5000)
                //{
                //    Thread.Sleep(10000);
                //}
            }

            //需要测试的模块   
            DreamCube.Foundation.Basic.Win32API.API.kernel32.QueryPerformanceCounter(ref count1);
            count = count1 - count;
            result = (double)(count) / (double)freq;
            Console.WriteLine("耗时: {0} 秒", result);
            Console.ReadLine();   
        }

        public static void StartTestDic()
        {
            Dictionary<String, String> d1 = new Dictionary<string, string>();
            d1.Add("lijian", "dd");

            Dictionary<Type, String> d2 = new Dictionary<Type, string>();
            d2.Add(typeof(String), "dd");

            Int32 repeatCount = 100000000;

            DCObject.PerformanceCounter sw = new DCObject.PerformanceCounter();
            sw.Start();
            for (Int32 i = 0; i < repeatCount; i++)
                d1.ContainsKey("d");
            sw.Stop();
            Type stringType = typeof(String);
            DCObject.PerformanceCounter sw2 = new DCObject.PerformanceCounter();
            sw2.Start();
            for (Int32 i = 0; i < repeatCount; i++)
            {
                d2.ContainsKey(stringType);
            }
            sw2.Stop();

            Console.WriteLine("字符串Key耗时:{0} 毫秒", sw.Milliseconds);
            Console.WriteLine("类型Key耗时:{0} 毫秒", sw2.Milliseconds);
        }

        public static void StartEx()
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (Int32 i = 0; i < 3; i++)
            {
                Thread.Sleep(1000);
            }
            sw.Stop();
            Console.WriteLine("耗时: {0} 秒", sw.Elapsed.Seconds);
        }
    }
}
